package com.hp.system.service.impl;

import com.hp.common.annotation.Log;
import com.hp.common.core.domain.AjaxResult;
import com.hp.common.enums.BusinessType;
import com.hp.system.domain.IdentifyInfo;
import com.hp.system.domain.IdentifyInfoExample;
import com.hp.system.domain.PassInfo;
import com.hp.system.mapper.IdentifyInfoMapper;
import com.hp.system.service.IdentifyInfoServce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Service
public class IdentifyInfoServceImpl implements IdentifyInfoServce {
    @Autowired(required = false)
    private IdentifyInfoMapper identifyInfoMapper;
    /**
     * 添加识别记录,若为重复记录则忽略
     * @param identifyInfo
     * @return
     */
    @Override
    public int addInfo(IdentifyInfo identifyInfo) {
        boolean isadd = true;
        int number = identifyInfoMapper.selectCountByisdeal(0);
        if(number>0){
            IdentifyInfoExample identifyInfoExample = new IdentifyInfoExample();
            IdentifyInfoExample.Criteria criteria = identifyInfoExample.createCriteria();
            criteria.andIsdealEqualTo(new Byte("2"));
            List<IdentifyInfo> list = identifyInfoMapper.selectByExample(identifyInfoExample);
            for (IdentifyInfo info: list
                    ) {
                if(info.getSerialno().equals(identifyInfo.getSerialno()) && info.getLicense().equals(identifyInfo.getLicense()))
                    isadd = false;
            }
        }
        if (isadd){
            return identifyInfoMapper.insertSelective(identifyInfo);
        }
        else
            return 0;
    }

    @Override
    public List<IdentifyInfo> selectByIdentify(IdentifyInfo identifyInfo) {
        List<IdentifyInfo> list = identifyInfoMapper.selectByIdentifyInfo(identifyInfo);
        return list;
    }

    @Override
    public IdentifyInfo selectById(Integer id) {
        return identifyInfoMapper.selectByPrimaryKey(id);
    }


}
